<?php

namespace app\admin\model;

use app\common\model\BaseModel;

/**
 * 后台用户模型
 * Class AdminUser
 * @package app\admin\model
 */
class AdminOperationLog extends BaseModel
{
    protected $name = 'admin_operation_log';

    protected $pk = 'admin_operation_log_id';
    /**
     * 追加字段
     * @var array
     */
    protected $append = [
        'AdminMenu',
        'AdminUser'
    ];
    
    /**
     * 隐藏字段
     * @var array
     */
    protected $hidden = [
        'password',
        'update_time'
    ];

    public function getCreateTimeAttr($value){
        return date('Y/m/d H:i',$value);
    }

    /**
     * 关联菜单表
     * @return \think\model\relation\BelongsTo
     */
    public function AdminMenu()
    {
        $module = self::getCalledModule() ?: 'common';
        return $this->belongsTo("app\\{$module}\\model\\AdminMenu");
    }

    /**
     * 关联菜单表
     * @return \think\model\relation\BelongsTo
     */
    public function AdminUser()
    {
        $module = self::getCalledModule() ?: 'common';
        return $this->hasOne("app\\{$module}\\model\\AdminUser",'admin_user_id','admin_user_id');
    }


    // 访问日志列表
    public function getAll(){
        return $this->with(['AdminMenu','AdminUser'])->order('create_time desc')
        ->paginate(15, false, [
            'query' => request()->request()
        ]);
    }

     // 添加访问记录
     public function add($param){
        $this->save($param);
    }


}